import os, sys
import pygame
from pygame.locals import *

class HeatmapDebug(pygame.sprite.DirtySprite):
    def __init__(self, heatmap, grid):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface([800, 800])
        self.image.set_colorkey((100,100,100))
        self.image.fill((100, 100, 100))
        # Make our top-left corner the passed-in location.
        self.rect = self.image.get_rect()
        self.rect.topleft = (0,0)
        for x in range(0, 800/grid):
            for y in range(0, 800/grid):
                if (heatmap[x][y]['d'] != 0) :
                    pygame.draw.rect(self.image, (min(255, heatmap[x][y]['d']*2), max(0, 255 - heatmap[x][y]['d']*2), max(0, 79 - heatmap[x][y]['d']/2)), pygame.Rect(x*grid,y*grid,grid,grid))

class LevelDebug(pygame.sprite.DirtySprite):
    def __init__(self, tree):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface([800, 800])
        self.image.set_colorkey((100,100,100))
        self.image.fill((100, 100, 100))
        # Make our top-left corner the passed-in location.
        self.rect = self.image.get_rect()
        self.rect.topleft = (0,0)

        leafs = tree.getLeafs()
        for leaf in leafs:
            if (leaf.points['nw'].neigh['e']):
                pygame.draw.line(self.image, (255, 255, 255), leaf.points['nw'].loc(), leaf.points['nw'].neigh['e'].loc())
            if (leaf.points['ne'].neigh['s']):
                pygame.draw.line(self.image, (255, 255, 255), leaf.points['ne'].loc(), leaf.points['ne'].neigh['s'].loc())
            if (leaf.points['se'].neigh['w']):
                pygame.draw.line(self.image, (255, 255, 255), leaf.points['se'].loc(), leaf.points['se'].neigh['w'].loc())
            if leaf.points['sw'].neigh['n']:
                pygame.draw.line(self.image, (255, 255, 255), leaf.points['sw'].loc(), leaf.points['sw'].neigh['n'].loc())

class CampDebug(pygame.sprite.DirtySprite):
    def __init__(self, camppoints, snipers):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface([800, 800])
        self.image.set_colorkey((100,100,100))
        self.image.fill((100, 100, 100))
        # Make our top-left corner the passed-in location.
        self.rect = self.image.get_rect()
        self.rect.topleft = (0,0)

        for p in camppoints:
            pygame.draw.circle(self.image, (255, 0, 255), p, 5)
        for p in snipers:
            pygame.draw.circle(self.image, (51, 100, 0), p, 5)

class AgentDebug(pygame.sprite.DirtySprite):
    def __init__(self, com_agents):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface([800, 800])
        self.image.set_colorkey((100,100,100))
        self.image.fill((100, 100, 100))
        # Make our top-left corner the passed-in location.
        self.rect = self.image.get_rect()
        self.rect.topleft = (0,0)
        #print com_agents
        for agent in com_agents:
            #print "line from: %s to %s" % (agent[4], agent[6])
            pygame.draw.line(self.image, (255, 255, 0), agent[4], agent[6])
